//
//  UIBarButtonItem-Extension.swift
//  liveDemo
//
//  Created by satoshi_uma on 2020/10/20.
//  Copyright © 2020 satoshi_uma. All rights reserved.
//

import UIKit

// 类似OC的类扩展
extension UIBarButtonItem {
//    类方法
//    class func createItem(imageName: String, hightImageName: String,size:CGSize) -> UIBarButtonItem {
//
//        let btn = UIButton()
//        btn.setImage(UIImage(named: imageName), for: .normal)
//        btn.setImage(UIImage(named: hightImageName), for: .highlighted)
//        btn.frame = CGRect(origin: CGPoint.zero, size: size)
//        return UIBarButtonItem(customView: btn)
//
//    }

    /// 便利构造函数
    /// 1. 必须以 convenience 开头
    /// 2. 必须明确的调用一个设计的构造函数（self）
    /// - Parameters:
    ///   - imageName: 图片名
    ///   - hightImageName: 高亮图片名
    ///   - size: 尺寸
    convenience init(imageName: String, hightImageName: String = "", size: CGSize = CGSize.zero) {
        
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), for: .normal)
        
        if hightImageName != "" {
            btn.setImage(UIImage(named: hightImageName), for: .highlighted)
        }
        
        if size == CGSize.zero {
            btn.sizeToFit()
        }else{
            btn.frame = CGRect(origin: CGPoint.zero, size: size)
        }

        self.init(customView: btn)
    }
}
